package com.ikun.admin.modules.auth.utils;

import com.alibaba.fastjson.JSON;
import com.ikun.common.result.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * ximeng
 */
public class ResponseUtils {


    /**
     * 向客户端写回去数据
     * @param resp
     * @param r
     */
    public static void sendResponse(HttpServletResponse resp, Result result) throws IOException {
        String jsonString = JSON.toJSONString(result);
        //然后将数据返回到客户端
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.write(jsonString);
        writer.flush();
        writer.close();
    }


}
